<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Score;
use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function getUser(User $user){
        $result = $user->get(['id' , 'username' , 'last_login_timestamp' , 'created_at' , 'reason'])->toArray();
        return view('user' , ['data' => $result]);
    }

    public function user($username){
        $user = User::with(['scores' => function($query){
            $query->with('game');
        }])->where('username' , $username)->get();
      return view('user_details' , ['data' => $user[0]]);
    }

    public function reason(Request $request){
        $data = $request->only(['id' , 'reason' , 'cause']);
        $reason = $data['reason'] == 'Disable' ? $data['cause'] : null;
        User::where('id' , $data['id'])->update(['reason' => $reason]);
        return redirect('Module_C/userList');
    }
}
